<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <#include "../common/include_easyui.ftl">
    <#assign ctx = request.contextPath>

    <script type="text/javascript">
        var ctxPath = "${ctx}";
        jQuery(function () {
            var toolBarArray = [
                {
                    id: "search", text: "查询数据", iconCls: "icon-search", handler: function () {
                        //组装json数据
                        var qryItem = jQuery("#qry_item").val();
                        var qryType = jQuery("#qry_type").val();
                        var paramObj = {
                            "qryItem": qryItem,
                            "qryType": qryType

                        };
                        jQuery("#div_table").datagrid({
                            queryParams: paramObj
                        });
                        jQuery("#div_table").datagrid("reload");

                    }
                },
                {
                    id: "add", text: "添加数据字典", iconCls: "icon-add", handler: function () {
                        addFun();
                    }
                },
                {
                    id: "edit", text: "修改数据字典", iconCls: "icon-edit", handler: function () {
                        editFun();
                    }
                },
                {
                    id: "delete", text: "删除数据字典", iconCls: "icon-remove", handler: function () {
                        deleteFun();
                    }
                },
                {id: "export", text: "导出数据", iconCls: "icon-redo"},
                {
                    id: "reoload", text: "刷新数据", iconCls: "icon-reload", handler: function () {
                        jQuery("#div_table").datagrid("reload");
                    }
                }
            ];
            jQuery("#div_table").datagrid({
                //字段的属性
                columns: [
                    [
                        {field: 'checkedId', checkbox: true},
                        {field: 'id', title: 'ID', width: 100, halign: "center", align: "center", sortable: true},
                        {field: 'type', title: '类别', width: 200, halign: "center", align: "center", sortable: true},
                        {field: 'item', title: '条目', width: 200, halign: "center", align: "center", sortable: true},
                        {field: 'value', title: '值', width: 200, halign: "center", align: "center"}
                    ]
                ],
                //加载网格的数据
                url: ctxPath + "/dataDictionaryMgrController/listDict?date=" + new Date() + "",
                //网格属性的设置
                fit: true,
                rownumbers: true,
                ctrlSelect: true,
                striped: true,
                toolbar: toolBarArray,
                fitColumns: true,
                //分页的属性
                pagination: true,
                pageList: [5, 8, 10, 15],
                pageSize: 8
            });

            function addFun() {
                //模态对话框
                var addURL = ctxPath + "/dataDictionaryMgrController/preAdd";

                jQuery('#dialog_div').dialog({
                    title: "新增数据字典",
                    width: 700,
                    height: 500,
                    closed: false,
                    cache: false,
                    modal: true,
                    //href: 		ctxPath+'/easyui/panel_01.jsp'		//只能加载页面中非javascript的内容。
                    content: "<iframe id=\"testIFrame\" src='" + addURL + "' width='99%' height='98%' scrolling='no'></iframe>",
                    buttons: [
                        {
                            id: "saveButton", text: "保存数据", iconCls: "icon-save", handler: function () {
                                callChild_saveData();
                            }
                        },
                        {
                            id: "closeButton", text: "关闭窗口", iconCls: "icon-cancel", handler: function () {
                                jQuery('#dialog_div').dialog("close");
                            }
                        }
                    ]
                });
            }

            function editFun() {
                //Dialog对话框
                var selectRows = jQuery("#div_table").datagrid('getSelections');
                if (selectRows.length == 0) {
                    jQuery.messager.alert('提示', '修改操作必须选择一行数据', 'warning');
                } else if (selectRows.length > 1) {
                    jQuery.messager.alert('提示', '修改操作只能选择一行数据，请重新选择', 'warning');
                    jQuery("#div_table").datagrid('clearSelections');
                } else {
                    var id = selectRows[0].id;

                    var editURL = ctxPath + "/dataDictionaryMgrController/preModify/" + id + "";
                    jQuery('#dialog_div').dialog({
                        title: "修改数据字典",
                        width: 700,
                        height: 500,
                        closed: false,
                        cache: false,
                        modal: true,
                        //href: 		ctxPath+'/easyui/panel_01.jsp'		//只能加载页面中非javascript的内容。
                        content: "<iframe id=\"testIFrame\" src='" + editURL + "' width='99%' height='98%' scrolling='no'></iframe>",
                        buttons: [
                            {
                                id: "saveButton", text: "保存数据", iconCls: "icon-save", handler: function () {
                                    callChild_saveData();
                                }
                            },
                            {
                                id: "closeButton", text: "关闭窗口", iconCls: "icon-cancel", handler: function () {
                                    jQuery('#dialog_div').dialog("close");
                                }
                            }
                        ]
                    });
                }
            }

            function deleteFun() {

                var selectRows = jQuery("#div_table").datagrid('getSelections');

                if (selectRows.length == 0) {
                    jQuery.messager.alert('提示', '删除操作至少选择一行数据', 'warning');
                } else {

                    $.messager.confirm('删除提示', '您确定要删除选中的数据字典吗？', function (flag) {
                        if (flag) {
                            var idArray = new Array();
                            for (var i = 0; i < selectRows.length; i++) {
                                var id = selectRows[i].id;
                                idArray.push(id);
                            }
                            var decDictIds = idArray.join(",");

                            var decURL = ctxPath + "/dataDictionaryMgrController/delDict?date=" + new Date() + "";

                            var paramObj = {'decDictIds': decDictIds};

                            jQuery.post(decURL, paramObj, function (responseData) {

                                var code = responseData.code;

                                if (code == "200") {
                                    $.messager.alert('我的消息', '数据字典信息删除成功！', 'info', function () {
                                        jQuery("#div_table").datagrid("reload");
                                    });

                                } else {
                                    $.messager.alert('我的消息', "数据删除出错，原因 ：" + responseData.message, 'error');
                                }

                            }, "json");
                        }
                    });


                }
            }

            function callChild_saveData() {
                var testIFrame = jQuery("#testIFrame")[0];
                var childWin = testIFrame.contentWindow;
                childWin.saveData();
            }
        });
    </script>

</head>

<body class="easyui-layout">
<div data-options="region:'north',title:'查询条件'" style="height:80px;padding-left:10px;padding-top:15px;background:#eee;">
    <input class="easyui-textbox" name="qry_type" id="qry_type" style="width:30%;max-width:270px;"
           labelAlign="right" data-options="label:'类别：'">
    <input class="easyui-textbox" name="qry_item" id="qry_item" style="width:30%;max-width:270px;"
           labelAlign="right" data-options="label:'条目：'">
</div>
<div data-options="region:'center'" style="padding:0px;background:#eee;">
    <div id="div_table"></div>
</div>
<div id="dialog_div" style="padding: 0px;"></div>
</body>
</html>
